﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>

<script type="text/javascript" src='<%=Url.Content("~/Scripts/json.js")%>'></script>

<div class="float-left form-wrap" style="font-size:12px;color:#6a6b6d;">
    <input name="txtName" type="text" value="Họ tên" style="font-size:12px;color:#6a6b6d;" id="txtName" onfocus="clearName()" onblur="defaultName()" >
    <div class="float-left" style="width:160px; text-align:center">
        <span id="lblhoten" class="size11" style="color:#ff0000"></span>
    </div>
         
    <input name="txtEmail" type="text" value="Thư điện tử (bắt buộc)" id="txtEmail" 
        class="float-left size12 light40 required email" style="font-size:12px;color:#6a6b6d;" onfocus="clearEmail()" onblur="defaultEmail()">
    <div class="float-left" style="width:160px; text-align:center">
        <span id="lblEmail" class="size11" style="color:#ff0000"></span>
    </div>
    
    <input name="txtPhone" type="text" value="Số điện thoại liên hệ" id="txtPhone" class="float-left size12 light40" style="font-size:12px;color:#6a6b6d;" onfocus="clearPhone()" onblur="defaultPhone()">
    <div class="float-left" style="width:160px; text-align:center">
        <span id="labPhone" class="size11" style="color:#ff0000"></span>
    </div>
    
    <textarea name="txtContent" rows="2" cols="20" id="txtContent" class="textarea size12 light40 float-left" onfocus="clearContent()" onblur="defaultContent()" style="font-family:Arial; line-height:13px;font-size:12px;color:#6a6b6d;">Nội dung câu hỏi( Để kết quả tư vấn đạt kết quả tốt, bạn hãy ghi mong muốn về không gian ở với số tầng, số phòng, diện tích rộng x dài)</textarea>
    <div class="float-left" style="width:160px;">
        <span id="lblContent" class="size11" style="color:#ff0000"></span>
    </div>

    <div class="float-left" style="width:160px; text-align:center">
        <input type="button" name="btnSubmit" value="Gửi Câu hỏi tư vấn" id="btnSubmit" onclick="sendQuestion()"
            class="size10 white bg-darkblue btn-feedback font-uppercase font-bold" style="width:116px;line-height:16px; margin-top:4px;">
    </div>
        
    <div class="float-left" style="width:160px; text-align:center">
        <img id="loading-img" src="../../Content/images/loading.gif" alt="đang xử lý ....." 
            width="25px" height="25px"/>
        <span id="lblMessage" class="size12 darkblue"></span>
    </div> 
</div>	

<script type="text/javascript">
    $("#loading-img").hide();

    function sendQuestion() {
        $("#loading-img").show();
        $("#lblMessage").html("");
        var hoTen = $("#txtName").val();
        var email = $("#txtEmail").val();
        var fone = $("#txtPhone").val();
        var body = $("#txtContent").val();
        
        var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
        if (email == '') {
            $("#lblMessage").html("Địa chỉ email không được bỏ trống!");
            $("#loading-img").hide();
            return;
        }
        else if (!emailReg.test(email)) {
            $("#lblMessage").html("Địa chỉ email không hợp lệ!");
            $("#loading-img").hide();
            return;
        }

        //var data = { emailInfo: { Name: hoTen, From: email, Fone: fone, Body: body} };
        var data = { emailInfo: hoTen + "~" + email + "~" + fone + "~" + body };
        var jsonData = $.toJSON(data);
//        alert(data);
        //alert(jsonData);

        $.ajax({
            url: '/DatCauHoi',
            type: 'POST',
            dataType: 'json',
            data: jsonData,
            contentType: 'application/json; charset=utf-8',
            success: function(data) {
                var message = data.mess;
                $("#lblMessage").html(message);
                $("#loading-img").hide();
            }
        });
        
    }
</script>